<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <title>demo1.html</title>

        <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
        <meta http-equiv="description" content="this is my page">
        <meta http-equiv="content-type"
            content="text/html; charset=UTF-8">
        <script type="text/javascript">
        
        function getXmlHttpRequest() {
           if (window.XMLHttpRequest) {
               return new XMLHttpRequest();
           } else if (window.ActiveXObject) {
               return new ActiveXObject("Microsoft.XMLHTTP");
           }
        }
        
        function getInfo(){
           try {
               var url = "/servlet/Server";
               req = getXmlHttpRequest();
               req.open("GET", url, true);
               req.onreadystatechange = callback;
               req.send(null);
               
               /* var url = "/servlet/Server"; 
               var param = "username=" +escape(username); 
          	   req = getXmlHttpRequest(); req.open("POST", url, true);
          	   req.setRequestHeader("CONTENT-TYPE","application/x-www-form-urlencoded");
          	   req.onreadystatechange = callback; req.send(param); */
           } catch(e) {
               alert(e.description);
           }
        }
        
        function callback() {
           if (req.readyState == 4) {
               if (req.status == 200) {
                  parseMessage();
               } else {
                  alert("not able to retrieve description: " + req.statusText)
               }
           }
        }
        
        function parseMessage() {
            var xmlDoc = req.responseXML;
            var node = xmlDoc.getElementsByTagName("info");
            var content = document.getElementById("display");
            var str = "共返回： " + node.length + " 条信息！<br/>";
            for (var i=0; i<node.length; i++) {
                str += "<b>" +　node[i].firstChild.nodeValue + "</b><br/>"
            }
            content.innerHTML = str;
        }
        
        </script>

    </head>

    <body>
        <table>
            <tr>
               <td>服务器返回的信息：</td>
            </tr>
            <tr>
               <td><div id="display"></div></td>
            </tr>
            <tr>
               <td><input type="button" onclick="getInfo()" value="GetInfo"></td>
            </tr>
        </table>
    </body>
</html>
